package com.itheima.contact.web;

import com.itheima.contact.domain.User;
import com.itheima.contact.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author ${Azer}
 * @LOVE,,,
 * @Date 2021/9/19 10:13
 */
//web层，控制器
@WebServlet("/queryAllUser")
public class QueryAllUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //浏览器没有发送的数据
        //实例化业务层
        UserService userService=new UserService();
        List<User> users = userService.findAllUsers();

        //把用户数据存储到request域中
        request.setAttribute("users",users);

        //转发请求 （同时把request域对象也随之转发）
        request.getRequestDispatcher("/list.jsp").forward(request,response);
    }
}
